package com.miya.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

/**
 * @DESC
 * @Author:Caixiaowei
 * @Date:2018/11/22
 * @Time:下午4:28
 */
@RestController
public class ThymeleafController {

    @GetMapping("/index")
    public ModelAndView index(){
        ModelAndView view  = new ModelAndView();
        view.addObject("title", "springboot2 learning...");
        view.addObject("desc", "springboot 2.x 版本学习。。。");
        view.setViewName("demo/index");
        return view;
    }

    @GetMapping("/index1")
    public String index1(HttpServletRequest request) {
        // TODO 与上面的写法不同，但是结果一致。
        // 设置属性
        request.setAttribute("title", "我的第一个WEB页面");
        request.setAttribute("desc", "欢迎进入battcn-web 系统");
        // 返回的 index 默认映射到 src/main/resources/templates/xxxx.html
        return "index";
    }
}
